package com.wanho.java157.controller;


import com.wanho.java157.Car;
import com.wanho.java157.Orders;
import com.wanho.java157.result.R;
import com.wanho.java157.vo.CustomerVo;
import com.wanho.java157.vo.GoodsVo;
import com.wanho.java157.vo.OrdersVo;
import com.wanho.java158.OrdersService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/core/orders")
public class OrdersController {
    @Resource
    private OrdersService ordersService;
//管理员显示页面
    @GetMapping("/index")
    public R listAll(){
        List<Orders> ordersList = ordersService.selectAll();
        return R.ok().data("list", ordersList).message("获取列表成功");
    }

    @DeleteMapping("/remove/{orderId}")
    public R removeById(
            @PathVariable Integer orderId) {
        boolean result = ordersService.deleteByOrderId(orderId);
        if (result) {
            return R.ok().message("删除成功");
        } else {
            return R.error().message("删除失败");
        }
    }


    @PutMapping("/update")
    public R updateById(
            @RequestBody Orders orders){
        boolean result = ordersService.update(orders) ;
        if(result){
            return R.ok().message("更新成功");
        }else{
            return R.error().message("更新失败");
        }
    }

    @PostMapping("/add")
    public R add(
            @RequestBody Orders orders){
        boolean result = ordersService.add(orders) ;
        if(result){
            return R.ok().message("增加成功");
        }else{
            return R.error().message("增加失败");
        }
    }





// 顾客显示页面
    @GetMapping("/customerList/{customerId}")
    public R list(
            @PathVariable Integer customerId){
        List<OrdersVo> ordersVos = ordersService.selectByCustomerIdList(customerId);
        return R.ok().data("list", ordersVos).message("获取个人订单列表成功");
    }

}
